<template>
	<view class="container">
		<block v-if="listData.length == 0">
			<view class="all_empty">
				<u-empty mode="data"></u-empty>
			</view>
		</block>
		<block v-else>
			<view class="order">
				<block v-for="(item, index) in listData" :key="index">
					<view class="order_li con_auto">
						<u-cell :title="item.create_time" :value="item.buyType == 'money' ? '现金购买' : '积分购买'"></u-cell>
						<view class="order_li_goods">
							<view class="logo">
								<image :src="httpbaseUrl + item.goods_image" mode=""></image>
							</view>
							<view class="desc">
								<view class="title u-line-2">名称:{{ item.goods_name }}</view>
								<view class="dc" v-if="item.buyType == 'money'">价格:{{ item.goods_price }}</view>
								<view class="dc" v-if="item.buyType == 'jf'">积分:{{ item.sale_integral }}</view>
								<view class="dc">
									<block v-if="item.status === 0">未兑换</block>
									<block v-if="item.status === 1">已兑换</block>
								</view>
							</view>
						</view>
						<u-line></u-line>
						<view class="order_li_btn">
							<!-- <view class="btn" style="background: #5ac725">出示二维码</view> -->
							<view class="btn" style="background: #5ac725" @click="setYes(item.id)" v-if="item.status == 0">已领取</view>
							<view class="btn" style="background: #f56c6c" @click="delOrder(item.id)">删除</view>
							<view class="btn" style="background: #3c9cff" @click="cancleOrder(item.id)" v-if="item.status === 0">不想要</view>
						</view>
					</view>
				</block>
				<view style="height: 24rpx"></view>
				<u-loadmore v-if="listData.length > searchForm.limit" :status="status" :loading-text="loadingText" :loadmore-text="loadmoreText" :nomore-text="nomoreText" />
			</view>
		</block>
	</view>
</template>

<script>
export default {
	data() {
		return {
			searchForm: {
				limit: 10,
				page: 1
			},
			listData: []
		};
	},
	onLoad() {
		this.getInfo();
	},
	methods: {
		setYes(id) {
			let _this = this;
			uni.showModal({
				showCancel: true,
				content:'您确定已经领取了吗？',
				success(btn) {
					if (btn.confirm) {
						_this
							.$http('order/setOrderStatus', {
								id
							})
							.then((res) => {
								if (res.code) {
									_this.$u.toast('设置成功');
									_this.getInfo();
								}
							});
					}
				}
			});
		},
		delOrder(id) {
			let _this = this;
			uni.showModal({
				showCancel: true,
				content: '您确定删除吗',
				success(btn) {
					if (btn.confirm) {
						_this
							.$http('reservation/userDelOrder', {
								id
							})
							.then((res) => {
								if (res.code) {
									_this.$u.toast('删除成功');
									_this.getInfo();
								}
							});
					}
				}
			});
		},
		cancleOrder(id) {
			let _this = this;
			uni.showModal({
				showCancel: true,
				content: '您确定取消吗',
				success(btn) {
					if (btn.confirm) {
						_this
							.$http('reservation/cancleOrder', {
								id
							})
							.then((res) => {
								if (res.code) {
									_this.$u.toast('取消成功');
									_this.getInfo();
								}
							});
					}
				}
			});
		},
		getInfo(is_add = false) {
			let _this = this;
			_this
				.$http('reservation/getReservationByList', {
					..._this.searchForm
				})
				.then((res) => {
					if (res.code) {
						if (is_add) {
							_this.listData = _this.listData.concat(res.data.data);
						} else {
							_this.listData = res.data.data;
						}
						console.log(_this.listData);
						if (_this.listData.length >= res.data.total) {
							this.status = 'nomore';
						} else {
							this.status = 'loadmore';
						}
					}
				});
		}
	}
};
</script>

<style lang="scss" scoped>
.order {
	background: #fff;
	&_li {
		padding-bottom: 20rpx;
		&_goods {
			display: flex;
			padding: 24rpx 0;
			.logo {
				width: 200rpx;
				height: 200rpx;
				image {
					width: 100%;
					height: 100%;
				}
			}
			.desc {
				height: 200rpx;
				display: flex;
				flex-direction: column;
				align-items: flex-start;
				justify-content: space-around;
				margin-left: 24rpx;
				flex: 1;
			}
		}
		&_btn {
			margin-top: 20rpx;
			display: flex;
			flex-direction: row;
			justify-content: flex-end;
			.btn {
				padding: 5rpx 10rpx;
				// border: 1rpx solid #ccc;
				border-radius: 10rpx;
				margin-right: 10rpx;
				color: #fff;
			}
		}
	}
}
</style>
